package com.ailk.aee.pcc.dao;

import com.ailk.aee.pcc.mongo.Mongo;
import com.asiainfo.simplecache.SimpleCache;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 用户同步状态
 *
 * @author pengzhang
 */
@Component
public class UserSyncDao {

    Mongo userSyncMongo;

    public DBObject querySyncColumnByUserId(String userId, String columnName, String channelName) {
        BasicDBObject query = new BasicDBObject("userId", userId);
        BasicDBObject fields = new BasicDBObject(channelName + "$" + columnName, 1);
        return userSyncMongo.getContentCollection().findOne(query, fields);
    }

    public void saveSyncColumnByUserId(String userId, String columnName, String value, String channelName) {
        BasicDBObject query = new BasicDBObject("userId", userId);
        BasicDBObject update = new BasicDBObject("$set", new BasicDBObject(channelName + "$" + columnName, value));
        userSyncMongo.getContentCollection().update(query, update, true, false);
    }
}
